<?php
$this->breadcrumbs = array(
	'申购单列表' => array(
		'index'
	),
	$model->project->name . ' (' . $model->submitDate . ')' => array(
		'view',
		'id' => $model->id
	),
	'更新内容',
);

$this->userActions = array(
	array(
		'label' => '新建申购单',
		'url' => array(
			'create'
		),
		'iconClass' => 'icon-basket-add'
	),
	array(
		'label' => '查看申购单',
		'url' => array(
			'view',
			'id' => $model->id
		),
		'iconClass' => 'icon-basket'
	),
	array(
		'label' => '管理申购单',
		'url' => array(
			'admin'
		),
		'iconClass' => 'icon-basket'
	),
);
?>

<h1>更新申购单内容</h1>
<div class="">
<div class="span-2"><?php echo CHtml::encode($model->submitDate);
					?></div>

<div class="span-3"><?php echo CHtml::encode($model->project->name); ?></div>
<div class="span-2">
	<?php echo CHtml::encode($model->getAttributeLabel('approverId')); ?>:
	<?php echo CHtml::encode($model->approver->fullName); ?>
</div>
<div class="span-2">
	<?php echo CHtml::encode($model->getAttributeLabel('warehouseManagerId')); ?>:
	<?php echo CHtml::encode($model->warehouseManager->fullName); ?>
</div>
<div class="span-4">
	<?php echo CHtml::encode($model->getAttributeLabel('token')); ?>:
	<?php echo CHtml::encode($model->token); ?>
</div>
<div class="clear"></div>
<?php if ($model->note) { ?>
<div><?php echo CHtml::encode($model->getAttributeLabel('note')); ?>:
	<?php echo CHtml::encode($model->note); ?></div>
<?php } ?>

</div>
<div>
<?php
$items = $model->items;
?>
<div class="update-items-grid">
<div class="form">
<?php echo CHtml::beginForm(array(
	'updateItems',
	'id' => $model->id
));
?>
<?php
$items = array_slice($model->items, 0);
$items[] = $newItem;

$this
	->widget('zii.widgets.grid.CGridView',
		array(
			'id' => 'material-requisition-items-grid',
			'dataProvider' => new CArrayDataProvider($items,
				array(
					'pagination' => false
				)),
			//'filter' => $model,
			'enablePagination' => false,
			'columns' => array(
				array(
					'header' => '',
					'type' => 'raw',
					'value' => '$row+1'
				),
				array(
					'header' => '物品',
					'type' => 'raw',
					'value' => 'Yii::app()->getController()
					->widget("widgets.material.JMaterialModelSelector",
					array(
						"model" => $data,
						"attribute" => "[$row]materialModelId",
						"unitInputId"=>CHtml::activeId($data, "[$row]unit"),
						"unitTextId"=>"item-standard-unit-$row",
						"onSelectCallback"=>"function(model){
	JX.Material.updateMaterialRequisitionHistory(model.id,\\"item-requisition-history-$row\\",\\"item-requisition-last-$row\\",'
						. '{id:' . $model->id . '});
}",
					), true);',
				//'footer' => $model->isBalanced() ? "" : "X"
				),
				array(
					'header' => '品牌',
					'type' => 'raw',
					'value' => 'CHtml::activeTextField($data, "[$row]brand",array("size"=>"8"));',
				//'footer' => '合计'
				),
				array(
					'header' => '数量',
					'type' => 'raw',
					'value' => 'CHtml::activeTextField($data, "[$row]amount",array("size"=>"3"));',
				),
				array(
					'header' => '单位',
					'type' => 'raw',
					'value' => 'CHtml::activeTextField($data, "[$row]unit",array("size"=>"3"));',
				),
				array(
					'header' => '折合',
					'type' => 'raw',
					'value' => 'CHtml::activeTextField($data, "[$row]amountStandardUnit",array("size"=>"3"));',
				),
				array(
					'header' => '标单',
					'headerHtmlOptions' => array(
						'style' => 'width: 32px;'
					),
					'type' => 'raw',
					'value' => '"<span id=\\"item-standard-unit-$row\\">".
					($data->materialModel?$data->materialModel->unit:"")."</span>"',
				),
				array(
					'header' => '申请人',
					'type' => 'raw',
					'filter' => CHtml::listData(
						Employee::findAllByTag('MATERIAL_REQUISITION_APPLICANT'), 'id', 'fullName'),
					'value' => '$this->grid->controller->widget("widgets.employee.JEmployeeSelector",array(
				"model"=>$data,
				"attribute"=> "[$row]applicantId",
				"tag"=>"MATERIAL_REQUISITION_APPLICANT",
				"relatedProjectName"=>"'.$model->project->name.'"
			),true);',
				//'footer' => Yii::app()->format->formatCurrency($model->totalCredit)
				),
				array(
					'header' => '备注',
					'type' => 'raw',
					'value' => 'CHtml::activeTextField($data, "[$row]note",array("size"=>"10"));',
				),
				array(
					'header' => '是否补交',
					'type' => 'raw',
					'value' => 'CHtml::activeDropDownList($data, "[$row]lateSubmit",JHTML::getBooleanValues());',
				//'footer' => Yii::app()->format->formatCurrency($model->totalCredit)
				),
				array(
					'header' => '已申购',
					'headerHtmlOptions' => array(
						'style' => 'width: 60px;'
					),
					'type' => 'raw',
					'value' => '"<span id=\\"item-requisition-history-$row\\">".
					($data->materialModelId?MaterialManager::getMaterialRequisitionHistory($data->materialModelId,
			' . $model->projectId . ',"' . $model->submitDate . '", "' . $model->id
						. '"):"")."</span>"',
				),
				array(
					'header' => '上次申购',
					'headerHtmlOptions' => array(
						'style' => 'width: 88px;'
					),
					'type' => 'raw',
					'value' => '"<span id=\\"item-requisition-last-$row\\">".
					($data->materialModelId?MaterialManager::getMaterialRequisitionLast($data->materialModelId,
			' . $model->projectId . ',"' . $model->submitDate . '", "' . $model->id
						. '"):"")."</span>"',
				),
				array(
					'class' => 'CButtonColumn',
					'template' => '{delete}',
					'deleteButtonUrl' => 'Yii::app()->controller->createUrl("deleteItem",array("id"=>$data->primaryKey))'
				),
			),
		));
?>
 
<?php echo CHtml::submitButton('添加/保存'); ?>
<?php echo CHtml::endForm(); ?>
</div><!-- form -->
</div>
</div>
